package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.bean.YNLike;
import com.github.postsanf.yinian.bean.YNStatus;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.github.postsanf.yinian.utils.StringUtils;
import com.github.postsanf.yinian.utils.YNUrlHelper;

public class ZanHistoryAdapter extends RecyclerView.Adapter<ZanHistoryAdapter.ViewHolder> {
    private Context context;
    private YNStatus mCurStatus;

    public ZanHistoryAdapter(Context context, YNStatus mCurStatus) {
        this.context = context;
        this.mCurStatus = mCurStatus;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        SimpleDraweeView avatar;
        ImageView avatartype;

        public ViewHolder(View itemView) {
            super(itemView);
            avatar = (SimpleDraweeView) itemView.findViewById(R.id.like_item_avatar);
            avatartype = (ImageView) itemView.findViewById(R.id.like_item_type);
        }

        public void bindData(YNLike viewBean) {
            if (!StringUtils.isEmpty(viewBean.getUpic())) {
                ImageOptHelper.showFrescoAvatar(Uri.parse(
                        YNUrlHelper.getAvatarUrl(context, viewBean.getUpic())), avatar, context);
                switch (viewBean.getLikeStatus()) {
                    case 2:
                        avatartype.setImageResource(R.drawable.timeline_face1);
                        break;
                    case 4:
                        avatartype.setImageResource(R.drawable.timeline_face2);
                        break;
                    case 5:
                        avatartype.setImageResource(R.drawable.timeline_face3);
                        break;
                    case 3:
                        avatartype.setImageResource(R.drawable.timeline_face4);
                        break;
                    case 0:
                        avatartype.setImageResource(R.drawable.timeline_face5);
                        break;
                }
            }
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.yn_tm_item_like, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.bindData(mCurStatus.getLike().get(position));
    }

    @Override
    public int getItemCount() {
        return mCurStatus.getLike().size();
    }


}
